#-*- coding:utf8 -*-
'''
Created on 2012-7-4

@author: Bise
'''
from lib.session import Session
import tornado.template
import tornado.web
import config

class BaseHandler(tornado.web.RequestHandler):
    def get_current_user(self):
        s = Session(self)
        islogin = s.get('login')
        if islogin == None or islogin is False:
            return None
        else:
            return True
        
    def display(self, tpl, **kwargs):
        #self.render(tpl, **kwargs)
        ''' 先用loader来实现，避免每次模板改动要重新启动服务'''
        try:
            loader = tornado.template.Loader(config.settings['template'])
            self.write(loader.load(tpl).generate(**kwargs))
        except:
            self.write('template error')
        
    def fetch(self, tpl, **kwargs):
        return self.render_string(tpl, **kwargs)
        